import { RouteRecordRaw } from 'vue-router'
import intersection from 'lodash-es/intersection'


export const filterAsyncRoutes = (routes: RouteRecordRaw[], modules: string[]): RouteRecordRaw[] => {
    const res: RouteRecordRaw[] = []
    routes.forEach(route => {
        const { auth } = route.meta || {}
        console.log(auth, 'auth');
        
        if (!auth) {
            if (route.children) {
                route.children = filterAsyncRoutes(route.children, modules)
            }
            res.push(route)
        } else {
            console.log(intersection(modules,auth), 'intersection(modules,auth)');
            
            if (intersection(modules,auth).length > 0) {
                if (route.children) {
                    route.children = filterAsyncRoutes(route.children, modules)
                }
                res.push(route)
            }
        }
    })
    return res
}